package com.zc.ex.userProvider.common;

import com.alibaba.fastjson.JSONObject;
import com.zc.ex.userProvider.model.UserInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class InitData {

    public static volatile Long seq = 4L;

    public static CopyOnWriteArrayList<UserInfo> userInfos = new CopyOnWriteArrayList<UserInfo>(){{
        add(new UserInfo(1L,"andy","","Andy"));
        add(new UserInfo(2L,"carl","","Carl"));
        add(new UserInfo(3L,"bruce","","Bruce"));
        add(new UserInfo(4L,"dolly","","Dolly"));
    }};

    public static Map<Long,UserInfo> userInfoIndex = new HashMap<>();

    static{
        if (userInfoIndex.isEmpty()){
            userInfoIndex = userInfos.stream().collect(Collectors.toMap(UserInfo::getId,item->item));
        }
    }

    public static void main(String[] args) {
        System.out.println(JSONObject.toJSON(userInfoIndex));
    }
}
